<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>同花顺热榜</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">			
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}			
		</style>				
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>
						
			window.onload = function() {			
			getSource(1);
			changeStyle();
			}
								
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource(1);
					temp = "";					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
		
			function changeStyle() {
				var obj = document.getElementById("towrite");								
				obj.style.left= "0px"; 				
				obj.style.width= "480px";	
				//obj.style.height= "620px";		
				obj.style.fontSize="12px";		
			}
			
			var k = "0";
			function getSource(s) {				
				var p1 = "<a href='javascript:void(0)' id='px1' onclick='getSource(" + "\"1\"" + ")'>" + "排名" + "</a>";
				var p2 = "<a href='javascript:void(0)' id='px2' onclick='getSource(" + "\"2\"" + ")'>" + "涨幅" + "</a>";
				var div = document.getElementById('towrite');
				//div.innerHTML = '<h3>同花顺热榜</h3>' + '<p style="margin-top:-10px;">排序（' + p1 + p2 + '）</p>';
				div.innerHTML = "<font size='3'><strong>同花顺热榜</strong><font size='1'>&nbsp;&nbsp;&nbsp;&nbsp;排序（" + p1 + p2 + "）</font></font><p>"; 
				aObj = document.getElementById('px' + s);											
				aObj.innerText = aObj.innerText + "↓";
				aObj.style.color = "#FFA07A"; 
				if(s == 1){
					k = 1;
				}else{
					k = 2;
				}				
				var url = "https://ai.iwencai.com/index/urp/getdata/basic?tag=同花顺热榜_每小时热股"; 				
				
				if (window.XMLHttpRequest) {
					xmlHttp1 = new XMLHttpRequest();					
				} else {
					xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");					
				}				
				xmlHttp1.onreadystatechange = writeSource;
				xmlHttp1.open("GET", url, true);
				xmlHttp1.send(null);				
			}
			
			function keepTwoDecimal(num) {  
				   var result = parseFloat(num);  
				   if (isNaN(result)) {  					  
					   return false;  
				   }  
				   result = Math.round(num * 100) / 100;  
				   return result;  
			};
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i] == undefined){
						break;
					}
					alist[i].style.color = "#d2d2d3"; //给所有a标签赋原色
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
			function writeSource() { 
				if (xmlHttp1.readyState == 4) {         
					var data = xmlHttp1.responseText									
					data = data.replace(/\s+/g,"");
					//document.write(data);	
					var aa = data.split('"datas":[{');
					var bb = aa[2].match(/(\S*),"meta"/)[1];
					//document.write(bb);
					if(k == 2){
						var h = bb.split('},{');
						var cc = "";
						for (i = 0; i < h.length; i++)
						{						
							if(h[i].indexOf('最新价') > -1){		
								cc += h[i] + "},{";
							}else{
								cc += h[i] + ',"最新价":"0","最新涨跌幅":"0"},{';
							}
						}
						
						//document.write(cc);
						cc = "[{" + cc.replace("}]},{","}]");
						var result = JSON.parse(cc);
						function up(a,b){					
							return b.最新涨跌幅-a.最新涨跌幅
						}					
							
						result.sort(up);
						result = JSON.stringify( result );
						result =result.replace(/,"最新价":"0","最新涨跌幅":"0"/g,'');
						//document.write(result);
						bb = result;
					}
					var ss = bb.split('},{');
					var div = document.getElementById('towrite');	
					//div.innerHTML = "";					
					var html = "";					
					for (i = 0; i < ss.length; i++)
					{	
						var code = ss[i].match(/\"股票代码\":\"(\S*)/)[1].split('","')[0];
						var name = ss[i].match(/\"股票名称\":\"(\S*)/)[1].split('","')[0];						
						var zfs = "";
						if(ss[i].indexOf('最新价') > -1){							
							var xj = ss[i].match(/\"最新价\":\"(\S*)/)[1].split('","')[0];
							var zf = ss[i].match(/\"最新涨跌幅\":\"(\S*)/)[1].split('","')[0];
							zf = keepTwoDecimal(zf);
							zfs = "&nbsp;&nbsp;现价：" + xj + "&nbsp;&nbsp;涨幅：" + zf + "%";
						}
						var ztyy = "";
						var xq = "";						
						if(ss[i].indexOf('涨停原因') > -1){							
							ztyy = ss[i].match(/\"涨停原因标题\":\"(\S*)/)[1].split('","')[0];
							xq = ss[i].match(/\"涨停原因揭秘\":\"(\S*)/)[1].split('","')[0];
							xq = xq.replace(/\\n/g, "<br>").replace(/\\"/g, '"');
							xq = '<p style="margin-top:2px;">' + ztyy + '</p><p style="margin-top:-5px;">' + xq + '</p>';
						}
						var gn = "";
						if(ss[i].indexOf('所属概念') > -1){
							gn = ss[i].match(/\"所属概念\":\"(\S*)/)[1].split('","')[0];													
						}
						var pm = ss[i].match(/\"个股热度排名名次\":(\S*)/)[1].split(',"')[0];						
						
						//alert(name);
						var jd = "<a href=http://www.treeid/code_" + code + " onclick='changeCss(this,\"towrite\")'>" + pm + " . " + code + "&nbsp;" + name + zfs + "</a>";						
						
						if(xq != ""){
							var jx = "<td><a href='javascript:void(0)' onclick='updates(" + "\"" + code + "\"" + ")' style='color:#fff'>" + "详情" + "</a></td>";							
							div.innerHTML += '<ul style="margin:1px">' + jd + "&nbsp;&nbsp;" + jx + "</ul>";
							//添加分类Div
							var newDiv1 = document.createElement("div");
							newDiv1.id = code;
							newDiv1.style.display = "none";
							document.getElementById("towrite").appendChild(newDiv1);
							div1 = document.getElementById(code);
							div1.innerHTML = div1.innerHTML + xq  ;							
							
						}else{
							div.innerHTML += '<ul style="margin:1px">' + jd + "</ul>";
						}
					}	
					//div.innerHTML = '<h3>同花顺热榜</h3><ul style="margin-top:-10px;margin-left:0px;">' + div.innerHTML + "</ul>";		
				}
			}
		
			var temp = "";			
			function updates(ss) {				
				if(document.getElementById(ss))
				{					
					div1 = document.getElementById(ss);
					if(temp.indexOf(ss) == -1)
					{
						temp += ss + ";";
						div1.style.display = "block";
						div1.style.border = "1px solid #646464";
						div1.style.color = "#FFA500";
						div1.style.whiteSpace = "normal";
					}
					else
					{
						temp = temp.replace(ss + ";" , "");
						div1.style.display = "none";
					}
				}								
			}
			
		</script>

	</head>

	<body>				
		<div id="towrite" class="fixedBox"></div>        
	</body>
</html>